//
//  CNPackageModel.swift
//  EmoticonKeyboard
//
//  Created by 陈锦聪 on 16/4/1.
//  Copyright © 2016年 Coco. All rights reserved.
//

import UIKit

class CNPackageModel: NSObject {
    
    /// 表情包文件夹
    var id: String
    /// 表情包名称
    var group_name_cn: String
    /// 表情模型数组
    var emoticons: [CNEmoticonModel]
    /// 表情页数组
    lazy var pageEmos: [[CNEmoticonModel]] = {
        var emos = [[CNEmoticonModel]]()
        let pageCount = (self.emoticons.count + CNEmoNumberOfPage - 1) / CNEmoNumberOfPage
        if pageCount == 0 {
            let emptyEmoticon = [CNEmoticonModel]()
//            print("before: \(emos)")
            emos.append(emptyEmoticon)
//            print("after: \(emos)")
            return emos
        }
        for i in 0..<pageCount {
            let location = i * CNEmoNumberOfPage
            var length = CNEmoNumberOfPage
            if location + length > self.emoticons.count {
                length = self.emoticons.count - location
            }
            let subEmos = (self.emoticons as NSArray).subarrayWithRange(NSRange(location: location, length: length)) as! [CNEmoticonModel]
            emos.append(subEmos)
        }
        return emos
    }()

    init(id: String, group_name_cn: String, emoticons: [CNEmoticonModel]) {
        self.id = id
        self.group_name_cn = group_name_cn
        self.emoticons = emoticons
        super.init()
    }
    
    override var description: String {
        return "\n\tPackageModel: [id: \(id), group: \(group_name_cn), emoticons: \(emoticons)]"
    }
}
